package com.hishop.common;

import com.hishop.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Redisson初始化
 * Created by hejie on 2018/4/8.
 */
@Component
@Slf4j
public class RedissonManager {
    private Config config = new Config();
    private Redisson redisson;
    private static String ip = PropertiesUtil.getProperty("redis.ip");
    private static Integer port = Integer.parseInt(PropertiesUtil.getProperty("redis.port"));
    private static String password = PropertiesUtil.getProperty("redis.password");
    private static String ip2 = PropertiesUtil.getProperty("redis2.ip");
    private static Integer port2 = Integer.parseInt(PropertiesUtil.getProperty("redis2.port"));
    private static String password2 = PropertiesUtil.getProperty("redis2.password");

    public Redisson getRedisson() {
        return redisson;
    }

    @PostConstruct
    private void init() {
        //单体服务
        config.useSingleServer().setAddress(ip + ":" + port);
        redisson = (Redisson) Redisson.create(config);
        log.info("Redisson初始化结束");
    }

}
